public class demo01 {
    public static void main(String[] args) {
        int[] arr={3,1,2};
        int n=getFirstUnFormedNum(arr);
        System.out.println(n);
    }
    //求正数数组的最小不可组成和
    public static int getFirstUnFormedNum(int[] arr) {
        int min = Integer.MAX_VALUE;
        int max = 0;
        for (int i = 0; i < arr.length; i++) {
            max += arr[i];
            min = Math.min(min, arr[i]);
        }
        boolean num[] = new boolean[max + 1];
        num[0] = true;
        for (int i = 0; i < arr.length; i++) {
            for (int j = max; j >= arr[i]; j--) {
                num[j] = num[j - arr[i]] || num[j];
            }
        }
        for (int i = min; i < num.length; i++) {
            if(!num[i]){
                return i;
            }
        }
        return max+1;
    }
}
